package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 成绩日志级别枚举
 *
 * <p>管理成绩记录的日志级别，包括调试、信息、警告、错误、严重等级别。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum GradeLogLevel implements BaseEnum {

    /** 调试级别 */
    DEBUG("DEBUG", "调试"),

    /** 信息级别 */
    INFO("INFO", "信息"),

    /** 警告级别 */
    WARNING("WARNING", "警告"),

    /** 错误级别 */
    ERROR("ERROR", "错误"),

    /** 严重级别 */
    CRITICAL("CRITICAL", "严重"),

    /** 跟踪级别 */
    TRACE("TRACE", "跟踪"),

    /** 通知级别 */
    NOTICE("NOTICE", "通知"),

    /** 警报级别 */
    ALERT("ALERT", "警报"),

    /** 紧急级别 */
    EMERGENCY("EMERGENCY", "紧急");

    private final String code;
    private final String description;

    GradeLogLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static GradeLogLevel fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Grade log level code cannot be null or empty");
        }

        for (GradeLogLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown grade log level code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static GradeLogLevel fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Grade log level description cannot be null or empty");
        }

        for (GradeLogLevel level : values()) {
            if (level.getDescription().equals(description)) {
                return level;
            }
        }
        throw new IllegalArgumentException("Unknown grade log level description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}